class Solution
{
public:
    int longestSubarray(vector<int> &nums)
    {
        // 按位与的结果一定不大于源操作数，只要找到最大值的最长重复序列
        int maxNum = 0;
        int maxLen = 1;
        int maxMaxLen = 0;
        for (int num : nums)
        {
            if (num > maxNum)
            {
                maxNum = num;
                maxLen = 1;
                maxMaxLen = 1;
            }
            else if (num == maxNum)
            {
                ++maxLen;
            }
            else
            {
                maxMaxLen = max(maxMaxLen, maxLen);
                maxLen = 0;
            }
        }
        maxMaxLen = max(maxMaxLen, maxLen);
        return maxMaxLen;
    }
};